<template>
  <div class="navBig">
    <!-- <div>{{ this.$route.params.id }}</div> -->
    <nav class="nav">
      <span class="back" @click="$router.go(-1)">&lt;</span> 面经详情
    </nav>

    <img
      class="img_p"
      src="https://img2.baidu.com/it/u=1340301861,717289068&fm=253&fmt=auto&app=138&f=JPEG?w=499&h=309"
      alt=""
    />

    <div class="d_content">
      <div class="d_content_title">
        <p>{{ detailList.title }}</p>
        <van-tag color="#e1f5f8" text-color="#39becd"> 近地铁 </van-tag>
      </div>

      <!-- 两端对齐 -->
      <van-row type="flex" justify="space-between" class="flex_bbox">
        <van-col span="6" class="flex_box">
          <p class="red_title">{{ detailList.price }}元/月</p>
          <p class="red_xia">租金</p>
        </van-col>
        <van-col span="6" class="flex_box">
          <p class="red_title">{{ detailList.roomType }}</p>
          <p class="red_xia">房型</p>
        </van-col>
        <van-col span="6" class="flex_box">
          <p class="red_title">{{ detailList.size }}㎡</p>
          <p class="red_xia">面积</p>
        </van-col>
      </van-row>

      <div class="type">
        <van-row type="flex">
          <van-col span="10" class="type_name">装修：<span>精装</span></van-col>
          <van-col span="10" class="type_name"
            >朝向：<span>{{ detailList.oriented[0] }}</span></van-col
          >
        </van-row>
        <van-row type="flex">
          <van-col span="10" class="type_name"
            >楼层：<span>{{ detailList.floor }}</span></van-col
          >
          <van-col span="10" class="type_name"
            >类型：<span>普通住宅</span></van-col
          >
        </van-row>
      </div>
      <!-- 地图占位 -->
      <div>小区:{{ detailList.community }}</div>
    </div>

    <!-- 底部fixed -->
    <div class="footer">
      <div class="footer_box" @click="getCollect" v-if="type==='add'">
        <img src="http://liufusong.top:8080/img/unstar.png" alt="收藏" />
        收藏
      </div>
      <div class="footer_box" @click="getCollect" v-else>
        <img src="http://liufusong.top:8080/img/star.png" alt="收藏" />
        收藏
      </div>
      <div class="footer_box">在线咨询</div>
      <div class="footer_box c_phone"><a href=" ">电话预约</a></div>
    </div>
  </div>
</template>

<script>
import { getHouseDetails } from '@/api/house'
import { addCollect, delCollect } from '@/api/user'
export default {
  name: 'Detail',

  data () {
    return {
      id: null,
      detailList: {},
      type: 'add'
    }
  },
  methods: {
    // 点击收藏
    async getCollect () {
      this.id = this.$route.params.id
      if (this.type === 'add') {
        await addCollect(this.id)
        // console.log(data + '添加')
        this.$toast.success('添加成功')
        this.type = 'remove'
      } else {
        await delCollect(this.id)
        // console.log(data + '删除')
        this.$toast.success('删除成功')
        this.type = 'add'
      }
      // console.log(this.id)
    }
  },

  // 获取当前详情页数据
  async created () {
    this.id = this.$route.params.id
    console.log(this.id)
    const { body } = await getHouseDetails(this.id)
    this.detailList = body
    console.log(body)
  }
}
</script>

<style scoped lang="less">
.nav {
  height: 44px;
  border-bottom: 1px solid #e4e4e4;
  line-height: 44px;
  text-align: center;
  background: #4fc08d;
  color: #fff;
  .back {
    font-size: 18px;
    color: #fff;
    position: absolute;
    left: 10px;
    top: 0;
    transform: scale(1, 1.5);
  }
}
.img_p {
  width: 375px;
  // height: 100px;
}
.d_content {
  margin: 16px 15px;
  width: 345px;
  height: 237px;
  .d_content_title {
    margin: 15px 10px;
  }
  .flex_bbox {
    border-top: solid 1px #ccc;
    .flex_box {
      width: 109px;
      height: 52px;
      // line-height: 1.15;
      // margin-left: 8px;
      min-width: 10px;
      .red_title {
        margin: 10px 0;
        color: #fa5741;
        font-size: 18px;
        height: 26px;
        line-height: 26px;
        text-align: center;
      }
      .red_xia {
        margin: 0;
        text-align: center;
        height: 26px;
        line-height: 26px;
        color: #999;
        font-size: 14px;
      }
    }
  }
  .type {
    border-top: solid 1px #ccc;

    margin-top: 30px;
    margin-bottom: 20px;
    margin-left: 10px;

    .type_name {
      margin-top: 10px;
      color: #ccc;
      font-size: 14px;
      span {
        color: black;
        margin-left: 3px;
      }
    }
  }
}
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  line-height: 50px;
  border-top: 1px solid #cecece;
  text-align: center;
  font-size: 17px;
  color: #999;
  background-color: #fff;
  display: flex;
  // justify-content: space-around;

  .footer_box {
    border-right: 1px solid #e8e8e9;
    flex: 1;
    img {
      width: 16px;
    }
  }
  .c_phone {
    background-color: #58b57f;
    a {
      display: block;
      color: #fff;
    }
  }
}
// .footer {
//   position: fixed;
//   bottom: 0;
//   left: 0;
//   height: 50px;
//   display: flex;
//   align-items: center;
//   .am-flexbox-item {
//     width: 130px;
//     text-align: center;
//     line-height: 50px;
//     color: #a39f9f;
//     background-color: #fff;
//     border: 1px solid #cecece;
//     img {
//       width: 16px;
//       height: 16px;
//       margin-right: 5px;
//     }
//   }
//   .button {
//     background-color: #21b97a;
//     a {
//       color: #fff;
//     }
//   }
// }
</style>
